package com.cls.system.service.impl;

import com.cls.common.entity.QueryRequest;
import com.cls.system.entity.ConfigureQualification;
import com.cls.system.mapper.ConfigureQualificationMapper;
import com.cls.system.service.IConfigureQualificationService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.annotation.Propagation;
import lombok.RequiredArgsConstructor;
import com.github.pagehelper.PageHelper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageInfo;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.Arrays;
import java.util.List;

/**
 * 申报/主持人配置表 Service实现
 *
 * @author slx
 * @date 2020-11-17 11:51:28
 */
@Service
@RequiredArgsConstructor
@Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
public class ConfigureQualificationServiceImpl extends ServiceImpl<ConfigureQualificationMapper, ConfigureQualification> implements IConfigureQualificationService {

    @Override
    public PageInfo<ConfigureQualification> findConfigureQualifications(QueryRequest request, ConfigureQualification configureQualification) {
        LambdaQueryWrapper<ConfigureQualification> queryWrapper = new LambdaQueryWrapper<>();
        // TODO 设置查询条件
        if(configureQualification.getConfigureId()!=null){
            queryWrapper.eq(ConfigureQualification::getConfigureId,configureQualification.getConfigureId());
        }
        queryWrapper.orderByDesc(ConfigureQualification::getCreateTime);
        PageHelper.startPage(request.getPageNum(), request.getPageSize());
        List<ConfigureQualification> list= this.list(queryWrapper);
        PageInfo pageInfo = new PageInfo(list);
        return pageInfo;
    }

    @Override
    public List<ConfigureQualification> findConfigureQualifications(ConfigureQualification configureQualification) {
	    LambdaQueryWrapper<ConfigureQualification> queryWrapper = new LambdaQueryWrapper<>();
		// TODO 设置查询条件
		return this.baseMapper.selectList(queryWrapper);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void createConfigureQualification(ConfigureQualification configureQualification) {
        this.save(configureQualification);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void updateConfigureQualification(ConfigureQualification configureQualification) {
        this.saveOrUpdate(configureQualification);
    }


    /**
    * 删除
    * @param ids
    */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public void deleteConfigureQualifications(String[] ids) {
        List< String > list = Arrays.asList(ids);
        this.removeByIds(list);
     }

    @Override
    public ConfigureQualification findByConfigureIdAndLevelType(Long configureId, String levelType) {
         return baseMapper.findByConfigureIdAndLevelType(configureId, levelType);
    }

}
